//
//  MCNewAcWuYue02ViewController.m
//  ZXZX
//
//  Created by menhao on 2018/5/9.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCNewAcWuYue02ViewController.h"
#import "MCNewActGetMoneyModel.h"
#import "MCNewActCharModel.h"
#import "MCMineInfoModel.h"
@interface MCNewAcWuYue02ViewController ()

@property (nonatomic,weak) UILabel *myLabel;
@property (nonatomic,weak) UIButton *btn;
@property (nonatomic,strong) MCNewActGetMoneyModel *getMoneyModel;
@property (nonatomic,strong) MCNewActCharModel *charModel;
@end

@implementation MCNewAcWuYue02ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpUI];
    self.navigationItem.title = @"活动详情";
//    [self loadData];
}
-(void)setUpUI{
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.view.backgroundColor = RGB(245, 245, 245);
    UIScrollView *bases = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:bases];
    
    bases.contentSize = CGSizeMake(G_SCREENWIDTH - MC_REALVALUE(26), G_SCREENHEIGHT);
    UIImageView *titleImageV = [[UIImageView alloc] init];
    [bases addSubview:titleImageV];
    titleImageV.image = [UIImage imageNamed:@"开业送.jpg"];
    
    [titleImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bases).offset(13);
        make.width.equalTo(@(G_SCREENWIDTH - MC_REALVALUE(26)));
        make.height.equalTo(@(92));
        make.top.equalTo(bases).offset(13);
        
    }];
    UIImageView *coverImgV = [[UIImageView alloc] init];
    coverImgV.image = [UIImage imageNamed:@"hdyjs"];
    [bases addSubview:coverImgV];
    [coverImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(titleImageV);
    }];
    UILabel *titleLabel =  [[UILabel alloc] init];
    [bases addSubview:titleLabel];
    titleLabel.text = @"开业大派送";
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.textColor = RGB(249, 84, 83);
    titleLabel.font = [UIFont boldSystemFontOfSize:MC_REALVALUE(14)];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleImageV.mas_bottom).offset(MC_REALVALUE(13));
        
    }];
    
    UILabel *titleSubLabel =  [[UILabel alloc] init];
    [bases addSubview:titleSubLabel];
    titleSubLabel.textAlignment = NSTextAlignmentLeft;
    titleSubLabel.text = @"活动时间：8月1日-8月3日 ";
    titleSubLabel.textColor = RGB(99, 99, 99);
    titleSubLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [titleSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleLabel.mas_bottom).offset(MC_REALVALUE(13));
        
    }];
    
    
    UILabel *lineTitleLabel =  [[UILabel alloc] init];
    [bases addSubview:lineTitleLabel];
    lineTitleLabel.backgroundColor = RGB(136, 136, 136);
    [lineTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleSubLabel.mas_bottom).offset(MC_REALVALUE(10));
        make.height.equalTo(@(0.5));
    }];
    
    
    UILabel *contentLabel =  [[UILabel alloc] init];
    [bases addSubview:contentLabel];
    contentLabel.text = @"活动内容：\n\n在活动期间内注册成功绑定资料，充值金额≥300元，本人奖励58元，上级奖励10元，活动期间每人只限一次活动机会。有任何疑问请联系在线客服。";
    contentLabel.textAlignment = NSTextAlignmentLeft;
    contentLabel.numberOfLines = 0;
    contentLabel.textColor = RGB(99, 99, 99);
    contentLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(lineTitleLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    
    
    UILabel *tiKuanInfoLabel =  [[UILabel alloc] init];
    [bases addSubview:tiKuanInfoLabel];
    tiKuanInfoLabel.numberOfLines = 0;
    tiKuanInfoLabel.text = @"提款说明：\n\n需消费（首次充值金额+活动奖励）的100%流水。";
    tiKuanInfoLabel.textAlignment = NSTextAlignmentLeft;
    tiKuanInfoLabel.textColor = RGB(99, 99, 99);
    tiKuanInfoLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [tiKuanInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(contentLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];


    

        UILabel *myLabel =  [[UILabel alloc] init];
        [bases addSubview:myLabel];
        myLabel.numberOfLines = 0;
        NSString *str = @"已充值金额：0元\n\n可领取金额：0元";
        NSArray *number = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
        myLabel.textColor = RGB(99, 99, 99);
        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:str];
        for (int i = 0; i < str.length; i ++) {
            NSString *a = [str substringWithRange:NSMakeRange(i, 1)];
            if ([number containsObject:a]) {
              [attributeString addAttributes:@{NSForegroundColorAttributeName:RGB(249, 84, 83),NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} range:NSMakeRange(i, 1)];
            }
        }
        self.myLabel = myLabel;
        myLabel.attributedText = attributeString;
        myLabel.textAlignment = NSTextAlignmentLeft;
    
        myLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
        [myLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(titleImageV);
            make.top.equalTo(tiKuanInfoLabel.mas_bottom).offset(MC_REALVALUE(20));
    
        }];
    


    UIButton *btn = [[UIButton alloc] init];
    [bases addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bases);
        make.top.equalTo(myLabel.mas_bottom).offset(MC_REALVALUE(40));
        make.height.equalTo(@(35));
        make.width.equalTo(@(100));
    }];
    

    btn.layer.cornerRadius = 6;
    btn.clipsToBounds = YES;
    btn.userInteractionEnabled = false;
    btn.backgroundColor = RGB(204, 204, 204);
    [btn setTitle:@"领取奖金" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13] ;
    [btn addTarget:self action:@selector(btnCLick) forControlEvents:UIControlEventTouchUpInside];
    self.btn = btn;
    
    UILabel *guizeLabel =  [[UILabel alloc] init];
    [bases addSubview:guizeLabel];
    guizeLabel.numberOfLines = 0;
    guizeLabel.text = @"禁止一切非正常手段的套利行为，一经发现，将冻结账号，没收奖励。本活动最终解释权归正信在线所有！";
    guizeLabel.textAlignment = NSTextAlignmentLeft;
    guizeLabel.textColor = RGB(46, 46, 46);
    guizeLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(11)];
    [guizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.bottom.equalTo(self.view.mas_bottom).offset(MC_REALVALUE(-50));
        
    }];
    
}
- (void)loadData{
    
    MCNewActGetMoneyModel *getMoneyModel = [[MCNewActGetMoneyModel alloc] init];
    self.getMoneyModel = getMoneyModel;
    [getMoneyModel refreashDataAndShow];
    __weak typeof(self) weakself= self;
    [BKIndicationView showInView:self.view];
    getMoneyModel.callBackSuccessBlock = ^(id manager) {
        NSString *str = @"";
        NSString *ReturnMoney = [NSString stringWithFormat:@"%@",manager[@"ReturnMoney"]];
        NSString *ReceiveMoney = [NSString stringWithFormat:@"%@",manager[@"ReceiveMoney"]];
        if ([ReturnMoney isEqualToString:@""] || [ReturnMoney intValue] == -2 || [@"0" isEqualToString:GetRealSNum(ReturnMoney)] ) {
            weakself.btn.backgroundColor = RGB(204, 204, 204);
            weakself.btn.enabled = NO;
          
            str =[NSString stringWithFormat:@"已充值金额：%d元\n\n可领取金额：0元",[ReceiveMoney intValue]];
        }else{
            weakself.btn.backgroundColor = RGB(0, 127, 172);
            weakself.btn.enabled = YES;
          
            str =[NSString stringWithFormat:@"已充值金额：%d元\n\n可领取金额：%@元",[ReceiveMoney intValue],GetRealSNum(ReturnMoney)];
        }
        NSArray *number = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:str];
        for (int i = 0; i < str.length; i ++) {
            NSString *a = [str substringWithRange:NSMakeRange(i, 1)];
            if ([number containsObject:a]) {
                [attributeString addAttributes:@{NSForegroundColorAttributeName:RGB(249, 84, 83),NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} range:NSMakeRange(i, 1)];
            }
        }
        weakself.myLabel.attributedText = attributeString;
        
    };
    
    getMoneyModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
        [SVProgressHUD showInfoWithStatus:manager.responseMessage];
    };
}
- (void)btnCLick{
    
//    //判断有没有绑银行卡
//
//    MCMineInfoModel *mineInfoModel = [MCMineInfoModel sharedMCMineInfoModel];
//    BOOL hasCard = [mineInfoModel.BankCardNumber length]>1?YES:NO;
//    if (!hasCard) {
//        [SVProgressHUD showInfoWithStatus:@"绑定银行卡后领取"];
//        return;
//    } else {
        MCNewActCharModel *charModel = [[MCNewActCharModel alloc] init];
        self.charModel = charModel;
        [charModel refreashDataAndShow];
        __weak typeof(self) weakself= self;
        [BKIndicationView showInView:self.view];
        charModel.callBackSuccessBlock = ^(id manager) {
            if ([manager[@"ReturnMoney"] floatValue] > 0) {
                [SVProgressHUD showInfoWithStatus:manager[@"Remarks"]];
                weakself.btn.backgroundColor = RGB(204, 204, 204);
                [weakself.btn setTitle:@"奖金已领取" forState:UIControlStateNormal];
                [weakself loadData];
            }
        };
        charModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
            [SVProgressHUD showInfoWithStatus:manager.responseMessage];
        };
//    }
    
}
@end



